﻿using Android;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using AndroidX.Core.App;
using AndroidX.Core.Content;
using 交互音乐播放器.中间件;

namespace InteractiveMusicPlayerMobile.安卓平台.辅助类
{
    public static class 系统权限
    {
        public static void 获取安卓所有文件访问权限()
        {
            MainActivity.运行时.打开授权所有文件夹管理权限窗口();
        }

        public static void 获取安卓存储访问权限(MainActivity 运行时)
        {
            if (判断安卓是否具有存储权限())
            {
                return;
            }
            else
            {
                ActivityCompat.RequestPermissions(运行时, new string[] { Manifest.Permission.ReadExternalStorage }, 1);
            }
        }




     

        public static void 获取安卓存储写入权限(MainActivity 运行时)
        {
            if (判断安卓是否具有存储写入权限())
            {
                return;
            }
            else
            {
                ActivityCompat.RequestPermissions(运行时, new string[] { Manifest.Permission.ReadExternalStorage }, 1);
                ActivityCompat.RequestPermissions(运行时, new string[] { Manifest.Permission.ManageExternalStorage }, 1);
                ActivityCompat.RequestPermissions(运行时, new string[] { Manifest.Permission.WriteProfile }, 1);

            }
        }

        private static bool 判断安卓是否具有存储写入权限()
        {
            
                System.Diagnostics.Debug.WriteLine(MainApplication.运行时);
            if (ContextCompat.CheckSelfPermission(MainApplication.运行时, Manifest.Permission.WriteExternalStorage) == Permission.Denied)
            {
                return false;
            }
            if (ContextCompat.CheckSelfPermission(MainApplication.运行时, Manifest.Permission.ManageExternalStorage) == Permission.Denied)
            {
                return false;
            }
            else { return true; }
        }

        private static bool 判断安卓是否具有存储权限()
        {
            System.Diagnostics.Debug.WriteLine(MainApplication.运行时);
            if (ContextCompat.CheckSelfPermission(MainApplication.运行时, Manifest.Permission.ReadExternalStorage) == Permission.Denied)
            {
                
                return false;
            }
            else { return true; }

        }


        public static void 获取安卓后台运行权限(MainActivity 运行时)
        {
            ActivityCompat.RequestPermissions(运行时, new string[] { Manifest.Permission.ForegroundService }, 1);
        }
        public static void 获取安卓网络访问权限(MainActivity 运行时)
        {
            ActivityCompat.RequestPermissions(运行时, new string[] { Manifest.Permission.Internet }, 1);
        }
    }
}
